home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
More Source
/
Libraries
/
SAT 2.3b4
/
Demo ƒ
/
HeartQuest demo ƒ
/
sHeart.p
< prev
next >
Wrap
Text File
|
1995-01-16
|
4KB
|
175 lines
{===============================================}
{================= Heart sprite unit ================}
{===============================================}
{ Example file for Ingemars Sprite Animation Toolkit. }
{ © Ingemar Ragnemalm 1992 }
{ See doc files for legal terms for using this code. }
unit sHeart;
{ Sprite unit. A sprite unit should include the following routines:}
{ Init-procedure, that initializes private bitmaps}
{ Setup-procedure, that sets variables other than the standard ones set by MakeSprite }
{ Handle-procedure, to be called once per iteration until the sprite dies }
{ Hittask-procedure (optional), for advanced collission handling. }
interface
uses
{$IFC UNDEFINED THINK_PASCAL}
Types, Quickdraw,
{$ENDC}
SAT, scores, sBonus, SoundConst, GameGlobals;
procedure InitHeart;
procedure SetupHeart (mp: SpritePtr);
procedure SetupBonusHeart (mp: SpritePtr);
implementation
var
heartFace: array[1..4] of FacePtr;
sofar: integer;
procedure InitHeart;
var
ii: integer;
begin
for ii := 1 to 4 do
heartFace[ii] := SATGetFace(135 + ii);
end;
procedure HandleHeart (me: SpritePtr);
var
mp: SpritePtr;
begin
if me^.kind <> -2 then
begin
me^.task := nil;
AddScore(10);
SATSoundPlay(PlinkSndH, 1, false);
sofar := sofar + 1;
if sofar mod 5 = 0 then
if SATRand(10) < 5 then
mp := SATNewSprite(-4, -31, SATRand(gSAT.offSizeV - 64) + 32, @SetupBonus)
else
mp := SATNewSprite(-4, gSAT.offSizeH, SATRand(gSAT.offSizeV - 64) + 32, @SetupBonus);
end
else
levelCompleted := false;
me^.mode := me^.mode + 1;
if me^.mode = 5 then
me^.mode := 1;
me^.face := heartFace[me^.mode];
me^.position.h := me^.position.h + me^.speed.h;
me^.position.v := me^.position.v + me^.speed.v;
if me^.position.h < 0 then
begin
me^.position.h := 0;
me^.speed.h := -me^.speed.h;
me^.speed.v := me^.speed.v + SATRand(3) - 2;
end;
if me^.position.h > gSAT.offSizeH - xsize then
begin
me^.position.h := gSAT.offSizeH - xsize;
me^.speed.h := -me^.speed.h;
me^.speed.v := me^.speed.v + SATRand(3) - 2;
end;
if me^.position.v < 0 then
begin
me^.position.v := 0;
me^.speed.v := -me^.speed.v;
me^.speed.h := me^.speed.h + SATRand(3) - 2;
end;
if me^.position.v > gSAT.offSizeV - 32 then
begin
me^.position.v := gSAT.offSizeV - 32;
me^.speed.v := -me^.speed.v;
me^.speed.h := me^.speed.h + SATRand(3) - 2;
end;
{ It shouldn't be totally still! }
if (me^.speed.v = 0) and (me^.speed.h = 0) then
begin
me^.speed.h := SATRand(7) - 4;
me^.speed.v := SATRand(7) - 4;
end;
end; {HandleHeart}
procedure HandleBonusHeart (me: SpritePtr);
var
mp: SpritePtr;
begin
if me^.kind <> -2 then
begin
me^.task := nil;
AddScore(10);
SATSoundPlay(plinkSndH, 1, false);
end
else
levelCompleted := false;
me^.mode := me^.mode + 1;
if me^.mode = 5 then
me^.mode := 1;
me^.face := heartFace[me^.mode];
me^.position.h := me^.position.h + me^.speed.h;
me^.position.v := me^.position.v + me^.speed.v;
if me^.position.h > gSAT.offSizeH - xsize then
begin
me^.position.h := gSAT.offSizeH - xsize;
me^.speed.h := -me^.speed.h;
me^.speed.v := me^.speed.v + SATRand(3) - 2;
end;
if me^.position.h < 0 then
begin
me^.position.h := 0;
me^.speed.h := -me^.speed.h;
me^.speed.v := me^.speed.v + SATRand(3) - 2;
end;
if me^.position.v > gSAT.offSizeV then
begin
me^.task := nil;
gotAllBonuses := false;
SATSoundPlay(miuiuH, 1, true);
end;
{ It shouldn't be totally still! }
if me^.speed.v <= 0 then
me^.speed.v := SATRand(3) + 3; {Alltid positiv!}
end; {HandleBonusHeart}
procedure SetupHeart (mp: SpritePtr);
begin
mp^.face := heartFace[1];
mp^.mode := SATRand(4) + 1; { ikonnummer }
SetRect(mp^.hotRect, -5 + 16, -15 + 32, 5 + 16, -5 + 32);
mp^.speed.h := SATRand(7) - 4;
mp^.speed.v := SATRand(7) - 4;
sofar := 0;
mp^.task := @HandleHeart; {default}
end;
procedure SetupBonusHeart (mp: SpritePtr);
begin
mp^.face := heartFace[1];
mp^.mode := SATRand(4) + 1; { ikonnummer }
SetRect(mp^.hotRect, -5 + 16, -15 + 32, 5 + 16, -5 + 32);
mp^.speed.h := SATRand(7) - 4;
sofar := 0;
mp^.task := @HandleBonusHeart;
mp^.speed.v := SATRand(5) + 2 - mp^.position.v div 100; {Alltid positiv! Stor negativ position ger större fart!}
end;
end.